var menuTree;
var oTable;
$(function() {

	var setting = {
		view : {
			selectedMulti : false
		},
		callback : {
			onClick : function(event, treeId, treeNode, clickFlag) {

				oTable.gridSearch([ {
					name : 'id',
					value : treeNode.id
				} ]);
			}
		},
		async : {
			enable : true,
			url : "${_BASE_PATH}/system/orgn/tree"
		}
	};
	menuTree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
	menuTree.selectNode(menuTree.getNodeByParam("id", "", null));

	oTable = $('#menutable').initDT({
		"sAjaxSource" : "${_BASE_PATH}/system/orgn/query",
		"check" : "multi"
	});

	$("#menutreeRefresh").click(function() {
		var node = menuTree.getNodeByParam("id", 0, null);
		menuTree.reAsyncChildNodes(node, "refresh");
	});

	$("#newMenuBtn").click(function() {
		$.dialog({
			id : "newMenuDialog",
			url : "${_BASE_PATH}/static/system_orgn_newOrgn"
		});
	});

	$("#modifyMenuBtn").click(function() {

		if (oTable.getSelectedIds().length != 1) {
			$.alert("只能修改一个部门。");
			return;
		}
		$.dialog({
			id : "modifyMenuDialog",
			url : "${_BASE_PATH}/system/orgn/get",
			data : {
				id : oTable.getSelectedIds()[0]
			}
		});

	});

	$("#delMenuBtn").click(function() {
		if (oTable.getSelectedIds().length == 0) {
			$.alert("请选择要删除的部门。");
			return;
		}

		$.confirm("确定要删除所选择的部门吗，如果部门下还有子部门都会被删除？", function() {
			$.ajax({
				url : "${_BASE_PATH}/system/orgn/del",
				data : {
					ids : oTable.getSelectedIds().toString()
				},
				success : function(result) {
					oTable.gridReload();
				}
			});
		});
	});
	$("#selectall").click(function() {
		oTable.selectAllRow();
	});
	$("#cancelall").click(function() {
		oTable.unSelectAllRow();
	});
});